<?php
namespace QuestionPlus\QuestionPlusBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

use Topxia\WebBundle\Controller\BaseController;

use Topxia\Common\ArrayToolkit;

class QuestionPlumberAdminController extends BaseController
{
	public function settingAction(Request $request)
	{
		$questionPlusSetting = $this->getSettingService()->get('question_plus', array());

        $default = array(
            'enabled'=> 1,
        );

        $questionPlusSetting = array_merge($default, $questionPlusSetting);

        if ($request->getMethod() == 'POST') {
            $questionPlusSetting = $request->request->all();
            $this->getSettingService()->set('question_plus', $questionPlusSetting);
            $this->getLogService()->info('question_plus', 'update_setting', "更新题库增强版设置", $questionPlusSetting);
            $this->setFlashMessage('success','题库增强版设置已保存！');
        }

        return $this->render('QuestionPlusBundle:QuestionPlumberAdmin:setting.html.twig', array(
            'questionPlusSetting' => $questionPlusSetting
        ));
	}

	protected function getSettingService()
    {
        return $this->getServiceKernel()->createService('System.SettingService');
    }
}